package top.fzqblog.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import top.fzqblog.firstapp.R;

/**
 * Created by 抽离 on 2017/10/7 0007.
 */

public class ImgTextAdapter extends BaseAdapter {

    private List<Map<String, Object>> list;

    private LayoutInflater layoutInflater;

    public ImgTextAdapter(List<Map<String, Object>> list, Context context) {
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if(list == null){
            return 0;
        }
        return list.size();
    }

    @Override
    public Object getItem(int i) {
       return  list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = layoutInflater.inflate(R.layout.img_text_layout, null);
        view.setPadding(8, 8, 8, 8);//设置间距
        ImageView imageView = view.findViewById(R.id.iv);
        TextView textView = view.findViewById(R.id.tv);
        imageView.setImageResource((Integer) list.get(i).get("iv"));
        textView.setText((String)list.get(i).get("tv"));
        return view;
    }
}
